﻿using AutoShuntingSchedule.Utility.Extension;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;
using AutoShuntingSchedule.DAL;
using AutoShuntingSchedule.DAL.Models.Sys;
using AutoShuntingSchedule.Utility;
using AutoShuntingSchedule.Utility.Core;
using AutoShuntingSchedule.UI;
using AutoShuntingSchedule.UI.Common;
using AutoShuntingSchedule.UI.Forms;

namespace AutoShuntingSchedule
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            MyConfig config = File.ReadAllText(MyEnvironment.RootPath("Configs/config.json")).ToObject<MyConfig>();
            GlobalConfig.Config = config;
            string message = "";
            bool flag = BaseLogic.InitDB(config.DbType, config.DbHost, config.DbName, config.DbUserName, config.DbPassword, ref message);
            if (!flag)
            {
                Console.Write(message);
                return;
            }
            else
            {
                //BaseLogic.InitTables();
            }

            //初始化log4net配置文件
            Logger.Init(File.ReadAllText(MyEnvironment.RootPath("Configs/log4net.config")));
            Logger.OperateInfo("开机");

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var login = new FLogin();
            login.ShowDialog();
            if (GlobalConfig.CurrentUser == null)
            {
                GlobalConfig.CurrentUser = new SysUser();
            }

            Application.Run(new MainFormWebStyle());
        }
    }
}
